package com.stoneapple.timesheet.ProjectServlet;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.stoneapple.timesheet.Constrain;
import com.stoneapple.timesheet.dao.ProjectDao;
import java.util.logging.Logger;

@SuppressWarnings("serial")
public class addProjectServlet extends HttpServlet {
	
		private static final Logger log=Logger. getLogger(addProjectServlet.class.getName());
		
		public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException{
			
			UserService userService = UserServiceFactory.getUserService();
			User user = userService.getCurrentUser();
			
			if (user == null) {
				String loginUrl = userService.createLoginURL(req.getRequestURI());
				resp.sendRedirect(loginUrl);

			} else {
				log.info("User Id: " + user);
				
				String projectcode = Constrain.checkNullString(req.getParameter("projectcode"));
				String projectname = Constrain.checkNullString(req.getParameter("projectname"));
				String detail=Constrain.checkNullString(req.getParameter("detail"));
				String employeecode=Constrain.checkNullString(req.getParameter("employeecode"));
				String description=Constrain.checkNullString(req.getParameter("description"));
				
				
					
				
				
				

				log.info("Project information:");
				log.info("Project Code: " + projectcode + ", project Name: " + projectname +",detail: "+detail +",employeecode : "+employeecode+",description : "+description );

			ProjectDao projectdao=ProjectDao.getInstance();
			projectdao.save(user.getUserId(), projectcode, projectname,detail,employeecode,description);
			
				resp.sendRedirect("/project");			
			}
		}
	}
		
		




